package com.qingcheng.controller.goods;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.pojo.goods.Goods;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.goods.Spu;
import com.qingcheng.service.goods.SpuService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/spu")
public class SpuController {

    @Reference
    private SpuService spuService;

    //批量上架
    @PostMapping("/putMany")
    public Result putMany(String[] ids){
        spuService.updatePutMany(ids);
        return new Result();
    }

    //上架商品
    @PostMapping("/put")
    public Result put(String id){
        spuService.updatePut(id);
        return new Result();
    }

    //下架商品
    @PostMapping("/pull")
    public Result pull(String id){
        spuService.updatePull(id);
        return new Result();
    }
      //审核商品方法
    @PostMapping("/audit")
    public Result audit(String id,String status,String message){
        spuService.updateAudit(id,status,message);
        return new Result();
    }

    @GetMapping("/findAll")
    public List<Spu> findAll(){
        return spuService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Spu> findPage(int page, int size){
        return spuService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Spu> findList(@RequestBody Map<String,Object> searchMap){
        return spuService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Spu> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  spuService.findPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Spu findById(String id){
        return spuService.findById(id);
    }


    //修改和新增spu数据共用同一个方法
    @PostMapping("/add")
    public Result add(@RequestBody Goods goods){
        spuService.saveGoods(goods);
        return new Result();
    }

    //根据id去查询spu数据
    @GetMapping("/findGoodsById")
    public Goods findGoodsById(String id){

        return spuService.findGoodsById(id);

    }


//    @PostMapping("/update")
////    public Result update(@RequestBody Spu spu){
////        spuService.update(spu);
////        return new Result();
////    }

    @GetMapping("/delete")
    public Result delete(String id){
        spuService.delete(id);
        return new Result();
    }

    //逻辑删除,修改对应的字段信息(is_delete)logic
    @GetMapping("/logicDelete")
    public Result logicDelete(String id){
        spuService.logicDelete(id);
        return new Result();
    }

    //查看回收站(被逻辑删除的商品),直接给findList传递查询参数is_delete = 1的条件


}
